# coding=utf-8
### -*- coding:utf-8 -*-
import urllib2
import urllib

def getHtml(url,values):
    user_agent='Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36'
    headers = {'User-Agent':user_agent}

    data = urllib.urlencode(values)

    response_result = urllib2.urlopen(url+'?'+data).read()
#    html = response_result.decode('utf-8')
    html = response_result
    return html

#获取数据
def requestCnblogs(index):
    print('请求数据')
    url = 'http://chengdu.xuexiaodaquan.com/youeryuan'
    value= {

    }
    result = getHtml(url,value)
    return result

def saveToFile(text):
    fo = open('1.txt', "ab+")  # 打开小说文件
    # 以二进制写入章节题目 需要转换为utf-8编码，否则会出现乱码
#    fo.write(('\r' + text + '\r\n').encode('UTF-8'))
    fo.write(text)
    fo.close()  # 关闭小说文件


saveToFile(requestCnblogs(1))
